<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/12/12
 * Time: 13:51
 */
namespace App\Services\BackendApi;

use App\Repositories\UserLevelRelationsRepository;
use App\Repositories\UserRepository;

class UserService extends CommonService
{
    protected $userRepository;
    protected $userLevelRelationsRepository;

    public function __construct(UserRepository $userRepository,
                                UserLevelRelationsRepository $userLevelRelationsRepository)
    {
        parent::__construct();
        $this->userRepository = $userRepository;
    }

    public function getUserList($request)
    {
        if ($request['reg_time_start'] > $request['reg_time_end'] ||
            $request['last_login_start_time'] > $request['last_login_end_time']) {
            return $this->responseJson(1010000);//开始时间大于结束时间
        }
        $data = $this->userRepository->getUserList($request);
        return $this->responseJson(0, $data);
    }

    public function info($userId)
    {
        $data = $this->userRepository->byIdInfo($userId);
        return $this->responseJson(0, $data);
    }

    /**
     * 直接的被邀请人列表
     */
    public function directBeInvited(Request $request)
    {
        if (empty($request->level)) {
            $level = 0;
        } else {
            $level = json_decode($request->level);
            if (!is_array($level)) {
                return $this->responseJson(422);
            }
        }
        return $this->invitedService->directBeInvited($this->user['user_id'], $level, $request->page);
    }


}